﻿<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="DataList控件.aspx.cs" Inherits="ProjectStudy.DataList控件" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
    <script src="Scripts/jquery-1.4.1-vsdoc.js" type="text/javascript"></script>
    <script src="Scripts/jquery-1.4.1.js" type="text/javascript"></script>
    <script src="Scripts/jquery-1.4.1.min.js" type="text/javascript"></script>

    <script type="text/javascript">
        $().ready(function () {
            $("#chkAll").click(function () {
                $("input[name='chkItem']").attr("checked", $("#chkAll").attr("checked"));
            });
        });

        function del() {
            var chks = $("input[name='chkItem']");
            var arr = [];
            for (var i = 0; i < chks.length; i++) {
                if (chks[i].checked) {
                    arr.push( $(chks[i]).parent().next().children().first().text());
                }
            }
            if (arr.length <= 0) {
                alert("请最少选择一个");
            }
            else {
                if (confirm("确认删除?") == true) {
                    $.ajax({
                        type: "Post",
                        url: "DataList控件.aspx/aa",
                        data: JSON.stringify({ s: arr }),
                        contentType: "application/json; charset=utf-8",
                        dataType: "json",
                        success: function (data) {
                            //返回的数据用data.d获取内容                                 
                            alert(data.d);
                        },
                        error: function (err) {
                            alert(err);
                        }
                    });
                }
            }
        }
    </script>
</head>
<body>
    <form id="form1" runat="server">
    <div>
    
        <br />
        <input  type="button" id="btnDelAll" value="删除" onclick="del()"/>
        <br />
    
        <asp:DataList ID="DataList1" runat="server">
            <HeaderTemplate>
                <table cellpadding="0" cellspacing="0" border="1"  style=" border-collapse:collapse; text-align:center;">
                    <tr>
                      <th><input  type="checkbox" id="chkAll"/></th>
                      <th>班级ID</th>
                      <th>班级名称</th>
                      <th>班级描述</th>
                      <th>删除标记</th>
                    </tr>
            </HeaderTemplate>

            <ItemTemplate>
                <tr>
                  <td><input type="checkbox" name="chkItem"/></td>
                  <td><asp:Label ID="Label1" runat="server" Text='<%# DataBinder.Eval(Container.DataItem, "id") %>'></asp:Label></td>
                  <td><asp:Label ID="Label2" runat="server" Text='<%# DataBinder.Eval(Container.DataItem, "className") %>'></asp:Label></td>
                  <td><asp:Label ID="Label3" runat="server" Text='<%# DataBinder.Eval(Container.DataItem, "classDesc") %>'></asp:Label></td>
                  <td><asp:Label ID="Label4" runat="server" Text='<%# DataBinder.Eval(Container.DataItem, "isDel") %>'></asp:Label></td>
                </tr>
            </ItemTemplate>

            <FooterTemplate>
               </table>
            </FooterTemplate>
        </asp:DataList></div>
    </form>
</body>
</html>
